Dart List operator +
Syntax & Examples


Syntax of List.operator +

The syntax of List.operator + operator is:

operator +(List<E> other) → List<E>

This operator + operator of List returns the concatenation of this list and other.

Parameters

ParameterOptional/RequiredDescription
otherrequiredthe list to concatenate with this list


✐ Examples

1 Concatenate integer lists

In this example,

  1. We create two lists named list1 and list2 containing integers.
  2. We use the + operator to concatenate list1 and list2.
  3. The resulting list contains elements from both lists in the order they were concatenated.
  4. We print the result to standard output.

Dart Program

void main() {
  List<int> list1 = [1, 2, 3];
  List<int> list2 = [4, 5, 6];
  List<int> result = list1 + list2;
  print(result);
}

Output

[1, 2, 3, 4, 5, 6]

2 Concatenate string lists

In this example,

  1. We create two lists named list1 and list2 containing strings.
  2. We use the + operator to concatenate list1 and list2.
  3. The resulting list contains elements from both lists in the order they were concatenated.
  4. We print the result to standard output.

Dart Program

void main() {
  List<String> list1 = ['a', 'b', 'c'];
  List<String> list2 = ['x', 'y', 'z'];
  List<String> result = list1 + list2;
  print(result);
}

Output

[a, b, c, x, y, z]

3 Concatenate double lists

In this example,

  1. We create two lists named list1 and list2 containing double values.
  2. We use the + operator to concatenate list1 and list2.
  3. The resulting list contains elements from both lists in the order they were concatenated.
  4. We print the result to standard output.

Dart Program

void main() {
  List<double> list1 = [1.1, 2.2, 3.3];
  List<double> list2 = [4.4, 5.5, 6.6];
  List<double> result = list1 + list2;
  print(result);
}

Output

[1.1, 2.2, 3.3, 4.4, 5.5, 6.6]

Summary

In this Dart tutorial, we learned about operator + operator of List: the syntax and few working examples with output and detailed explanation for each example.